/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controllers;

import db.DriverDAO;
import db.EventDAO;
import db.TimeSlotDAO;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 *
 * @author bkazek11
 */
public class MethodsToImplement {

    //NEEDED FOR METHOD
    List<Driver> drivers;
    List<TimeSlot> driverTimeSlots;
    //GET POSSIBLE DRIVERS FOR AN EVENT
    public List<Driver> getPossibleDrivers(Service service) {
        //Can remove service paramater, put into event and go via
        //service id in event
        drivers = DriverDAO.getDrivers();
        ArrayList<Driver> possibleDrivers = new ArrayList<Driver>();

        for (Driver d : drivers) {
            driverTimeSlots = TimeSlotDAO.getTimeSlotsByDriver(d.getId());
            for (TimeSlot ts : driverTimeSlots) {
                if (ts.getStartTime().before(service.getStartTime())
                        && ts.getEndTime().after(service.getEndTime())
                        && ts.getWeekday().equals(service.getDay())) {
                    possibleDrivers.add(d);
                    break;
                }
            }
        }

        return possibleDrivers;
    }


    //NEEDED FOR METHOD
    List<Event> events;
    //SORTER FOR EVENTS BY POSSIBLE DRIVERS
    public void sortEventsByPossibleDrivers() {
        Collections.sort(events, possDriverComparator);
    }
    Comparator<Event> possDriverComparator = new Comparator<Event>() {

        @Override
        public int compare(Event e1, Event e2) {
            if (e1.getPossibleDrivers().size() //e1 has less drivers
                    < e2.getPossibleDrivers().size()) {
                return -1;
            } else if (e1.getPossibleDrivers().size() //e1 has more drivers
                    > e2.getPossibleDrivers().size()) {
                return 1;
            } else { //same number of drivers
                return 0;
            }
        }
    };
}
